#ifndef ICC_H_
#define ICC_H_

typedef struct {
        uint8_t bit_reverse;    /* bit logic convention */
        uint8_t t1;             /* T1 or T0 */
        uint8_t rec_byte;       /* received byte */
        uint8_t parity_count;   /* event parity counter */
        uint8_t IFSC;
        uint8_t NAD;
        uint8_t wtx;
        uint8_t IFD_Seq;
        uint8_t ICC_Seq;
        uint8_t IFSD_Negotiated;
        uint32_t etu_count;     /* ETU */
        uint32_t D;             /* D factor */
        uint32_t F;             /* F factor */
        uint32_t WWT;           /* work waiting time 960 * D * WI */
        uint32_t CWT;           /* character waiting time 2^CWI + 11 */
        uint32_t BWT;           /* block waiting time 2^BWI * 960 + 11 */
        uint32_t BGT;
        uint32_t GTR;
}icc_ctrl_t;

#define ERR_ATR_START_TIMEOUT   -1001
#define ERR_ATR_BYTE_TIMEOUT    -1002
#define ERR_ATR_TIMEOUT         -1003
#define ERR_ATR_TS              -1004
#define ERR_ATR_PARITY          -1005
#define ERR_ATR_TCK_T0          -1006
#define ERR_ATR_TCK_T1          -1007
#define ERR_INVALID_SW          -1008
#define ERR_SEND_PARITY         -1009
#define ERR_RECV_TIMEOUT        -1010
#define ERR_RECV_PARITY         -1011
#define ERR_RECV_LRC            -1012
#define ERR_INVALID_NAD         -1013
#define ERR_INVALID_LEN         -1014
#define ERR_ABORT_T1            -1015
#define ERR_SETIFSD_FAILURE     -1016
#define ERR_INVALID_INF         -1017
#define ERR_MAX_RETRIED         -1018
#define ERR_IFSD_ERROR          -1019

void wait_icc_clocks(uint32_t clocks);
void config_icc_timer_clocks(uint32_t n, uint32_t clocks);
void calc_icc_timer_etus(uint32_t n, uint32_t etus);
void config_icc_timer_etus(uint32_t n);
int check_icc_timer(uint32_t n);

#endif /* ICC_H_ */
